package com.coocare.licence.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.coocare.licence.entity.SysDictItem;
import com.coocare.licence.mapper.SysDictItemMapper;
import com.coocare.licence.service.ISysDictItemService;
import com.coocare.licence.utils.EmptyUtil;
import com.coocare.licence.utils.PageDomain;
import com.coocare.licence.utils.PageUtils;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 字典项 服务实现类
 * </p>
 *
 * @author adam
 * @since 2023-12-11
 */
@Service
public class SysDictItemServiceImpl extends ServiceImpl<SysDictItemMapper, SysDictItem> implements ISysDictItemService {

    @Override
    @CacheEvict(value = "dict_details", key = "#itemValue")
    public SysDictItem getByItemValue(String itemValue) {
        return getOne(Wrappers.lambdaQuery(SysDictItem.class)
                .eq(SysDictItem::getItemValue, itemValue));
    }

    @Override
    public PageUtils queryDictItemPage(Long dictId, String description, PageDomain pageDomain) {
        return new PageUtils(page(new Page<>(pageDomain.getPageNo(), pageDomain.getPageSize()), Wrappers.lambdaQuery(SysDictItem.class)
                .eq(SysDictItem::getDictId, dictId)
                .like(EmptyUtil.isNotEmpty(description), SysDictItem::getDescription, description)));
    }
}
